package org.codeCard.dialog;

import com.tool.role.RoleData;
import come.tool.JDialog.TiShiChuLi;
import org.cbg.bean.SearchGoodsBean;
import org.codeCard.bean.TbSaleCardOrderExt;
import org.codeCard.panel.CodeCardBuyJPanel;
import org.come.Frame.ZhuFrame;
import org.come.bean.LoginResult;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.GsonUtil;

public class ConfirmBuyCardJDialog implements TiShiChuLi {
    @Override
    public void tipBox(boolean tishi, Object object) {
        if (tishi) {

            TbSaleCardOrderExt saleCardOrder = (TbSaleCardOrderExt) object;

            LoginResult login = RoleData.getRoleData().getLoginResult();
            if(login.getGold().compareTo(saleCardOrder.getSalePrice()) < 0){
                ZhuFrame.getZhuJpanel().addPrompt2("#R金钱不够，购买失败!!");
                return;
            }

            String sendmes = Agreement.getAgreement().saleCardBuyAgreement(
                    GsonUtil.getGsonUtil().getgson().toJson(saleCardOrder));
            SendMessageUntil.toServer(sendmes);

            new Thread(()->{
                try {
                    Thread.sleep(1000L);
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    CodeCardBuyJPanel.FLAG = true;
                    searchGoodsBean.setSaletype(1);
                    searchGoodsBean.setPageNum(1);
                    String msg = Agreement.getAgreement().saleCardSearchAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(msg);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }).start();
        }
    }
}
